package com.yu.waterstation.system.modules.app.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.waterstation.common.common.annotation.AdminLog;
import com.yu.waterstation.common.common.annotation.NeedPermission;
import com.yu.waterstation.common.common.exception.ServiceException;
import com.yu.waterstation.common.common.util.result.Result;
import com.yu.waterstation.common.entity.app.TicketOrder;
import com.yu.waterstation.common.entity.system.vo.StudentVO;
import com.yu.waterstation.system.common.util.session.SessionUtil;
import com.yu.waterstation.system.modules.app.service.impl.TicketOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.INTERNAL;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "订单管理")
@RestController
@RequestMapping("/system/ticketOrder")
public class TicketOrderController {

    @Resource
    private TicketOrderService ticketOrderService;

    @ApiOperation("分页查询")
    @NeedPermission("system:ticketGoods:list")
    @GetMapping("/page")
    public Result<Page<TicketOrder>> selectPage(
            @RequestParam(defaultValue = "1") int pageNo,
            @RequestParam(defaultValue = "10") int pageSize)   {
        return Result.ok(ticketOrderService.selectPage(pageNo, pageSize));
    }

    @ApiOperation("所有处理中的订单")
    @NeedPermission("system:ticketGoods:list")
    @GetMapping("/handling")
    public Result<List<TicketOrder>> selectOrderHandling()   {
        return Result.ok(ticketOrderService.selectOrderHandling());
    }

    @ApiOperation("完成订单")
    @AdminLog
    @NeedPermission("system:ticketGoods:update")
    @PutMapping("/finish/{orderId}")
    public Result<Integer> finishOrder(@PathVariable Integer orderId, HttpServletRequest request)   {
        return Result.ok(ticketOrderService.finishOrder(orderId, SessionUtil.getCurrentSysUserUsername(request)));
    }

    @ApiOperation("取消订单")
    @AdminLog
    @NeedPermission("system:ticketGoods:update")
    @PutMapping("/cancel/{orderId}")
    public Result<Integer> cancelOrder(@PathVariable Integer orderId, HttpServletRequest request)   {
        return Result.ok(ticketOrderService.cancelOrder(orderId, SessionUtil.getCurrentSysUserUsername(request)));
    }

}
